package com.huanletao.spring.scheduling;

/**
 * <p>
 * </p>
 * package: com.huanletao.spring.scheduling
 * description:
 * className: demo
 * author:  踏雪无痕
 * copyright: Copyright (c) 2022/8/23 11:50
 * since: 1.0.0
 */
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;

/**
 * @author lyd
 * @Description:
 * @date 15:23
 */
@Configuration
public class ThreadSchedulerConfig {

    /**
     * 线程存储器
     */
    public static ConcurrentHashMap<String, ScheduledFuture> map = new ConcurrentHashMap<String, ScheduledFuture>();


    @Bean
    public ThreadPoolTaskScheduler threadPoolTaskScheduler(){
        ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
        // 配置池子的大小
        threadPoolTaskScheduler.setPoolSize(20);
        // 设置名字
        threadPoolTaskScheduler.setThreadNamePrefix("taskExecutor-");
        // 设置等待任务在关机时完成
        threadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown(true);
        // 设置等待终止时间
        threadPoolTaskScheduler.setAwaitTerminationSeconds(60);
        threadPoolTaskScheduler.setDaemon(true);

        return threadPoolTaskScheduler;
    }
}
